﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Helpers;

namespace MallInteractiveMap.Language
{
    public static class LanguageLoader
    {

        private static Object threadLock = new Object();
        /// <summary>
        /// Gets the value from the resource dictionary with the provided key.
        /// </summary>
        /// <param name="key">The key to search from the Dictionary.</param>
        /// <returns>The value of the provided key.</returns>
        public static string GetText(string key)
        {
            try
            {
                lock (threadLock)
                {
                    string strLookup = Properties.Resources.ResourceManager.GetString(key, Thread.CurrentThread.CurrentUICulture);
                    return strLookup;
                }
            }
            catch (System.ArgumentNullException)
            {
                //log to file
                return string.Empty;
            }
            catch (System.InvalidOperationException)
            {
                //log to file
                return string.Empty;
            }
            catch (System.Resources.MissingManifestResourceException)
            {
                //log to file
                return string.Empty;
            }
        }

        public static LanguageType CurrentLanguageType
        {
            get
            {
                switch (Thread.CurrentThread.CurrentUICulture.Name)
                {
                    case Constants.Culture.US:
                        return LanguageType.English;
                    case Constants.Culture.Arabic:
                        return LanguageType.Arabic;
                    default:
                        return LanguageType.English;

                }
            }
        }
        
    }

    public enum LanguageType
    {
        English = 1,
        Arabic = 2
    }
}
